package com.myproject.musicrecommendationsystem.controller;

import com.myproject.musicrecommendationsystem.domain.Playlist;
import com.myproject.musicrecommendationsystem.service.PlaylistService;
import com.myproject.musicrecommendationsystem.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@Api(tags="歌单功能(0729单禹铭)")
public class PlaylistController {
    @Autowired
    private PlaylistService service;
    @PostMapping("/addPlayList")
    @ApiOperation("新建歌单")
    public AjaxResult addPlayList(@RequestBody @Valid Playlist playlist){
//        if(playlist.hasErrors()){}
        service.createPlayList(playlist,playlist.getPlaylistSong());
        return AjaxResult.success("歌单创建成功");
    }
    @GetMapping("/getPlaylist")
    @ApiOperation("查询歌单id查询歌单")
        public AjaxResult getPlaylist(@RequestParam("id" )int id){
        return AjaxResult.success(service.selectById(id));
    }
    @DeleteMapping("/deletePlaylist")
    @ApiOperation("根据ID删除歌单")
    public AjaxResult deletePlaylist(int id){
        return AjaxResult.success(service.removeById(id));
    }

}
